package graphics;

import java.awt.Graphics;
import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

/**
 * Free draw represents a free shape
 * 
 * @author Jie Zhao(288654)
 * 
 */
public abstract class FreeDraw extends Shape {
	protected List<Point> points = null;
	protected boolean isFinalized = false;

	public FreeDraw() {
		super();
		points = new ArrayList<Point>();
	}

	/**
	 * Add a point
	 * 
	 * @param p
	 */
	public void addPoint(Point p) {
		points.add(p);
	}

	/**
	 * Return the number of points in this free draw
	 * 
	 * @return
	 */
	public int getNumofPoints() {
		return points.size();
	}

	protected int[][] producePointsSet() {
		int[][] result = new int[2][points.size()];
		for (int i = 0; i < points.size(); i++) {
			result[0][i] = points.get(i).x;
			result[1][i] = points.get(i).y;
		}
		return result;
	}

	/**
	 * finish drawing this freedraw
	 */
	public void finalize() {
		isFinalized = true;
	}

	/**
	 * 
	 * @return true if it has been finalized; false if not
	 */
	public boolean isFinalized() {
		return isFinalized;
	}

	/**
	 * 
	 * @return the last point in this free draw
	 */
	public Point getLastPoint() {

		if (points.size() > 0) {
			if (isFinalized())
				return new Point(points.get(points.size() - 1));
			return points.get(points.size() - 1);
		} else {
			return null;
		}
	}

	@Override
	/**
	 * draw this free shape
	 */
	public void draw(Graphics g) {
		super.draw(g);
	}
}
